package com.taotao.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.pojo.TbItemCat;
import com.taotao.service.ItemCatService;

@Controller
@RequestMapping("/item/cat")
public class ItemCatController {
	@Autowired
	ItemCatService itemCatService;
	
	@RequestMapping("/list")
	@ResponseBody
	public List<Object> getTbItemCatList(@RequestParam(defaultValue="0",value="id") Long parentId) {
		 List<TbItemCat> itemCatList = itemCatService.getItemCatList(parentId);
		 List<Object> catList = new ArrayList<>();
		 for(TbItemCat tbItemCat : itemCatList) {
			 Map<String,Object> node = new HashMap<>();
			 node.put("id", tbItemCat.getId());
			 node.put("text", tbItemCat.getName());
			 node.put("state",tbItemCat.getIsParent()?"closed":"open");
			 catList.add(node);
		 }
		 return catList;
	}

}
